# $Id: Makefile,v 1.2 2011/06/29 07:02:16 pgurumur Exp $
# Copyright (c) 2009 Prabhu Gurumurthy  <pgurumur@gmail.com>
# 
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

# version "$Revision: 1.2 $"
# author "$Author: pgurumur $"

LIBRARY := shl
UNAME	:= $(shell uname)
CC := g++
OBJS  := $(patsubst %.cpp,%.o,$(wildcard *.cpp))
OBJS  += $(patsubst %.c,%.o,$(wildcard *.c))
CFLAGS := -O4 -fPIC -W -Wall -Werror -Wextra  -I.
LDFLAGS :=
BUILD_OPTS := -fPIC -shared
STRIP	:= strip
ifeq ($(UNAME), OpenBSD)
CFLAGS += -I/usr/local/include/ -I/usr/local/include/tcl8.5 
LDFLAGS += -L/usr/local/lib -ltcl85 -lsource-highlight
LIBRARY := $(LIBRARY).so
endif

ifeq ($(UNAME), Linux)
CFLAGS += -I/usr/local/include
LDFLAGS += -ltcl8.5 -lsource-highlight
LIBRARY := $(LIBRARY).so
endif

ifeq ($(UNAME), Darwin)
CFLAGS += -I/usr/include/subversion-1 -I/usr/include/apr-1 
CFLAGS += -arch ppc -arch i386 -arch x86_64 -universal 
LDFLAGS += -L/usr/lib -lsource-highlight -ltcl8.5
BUILD_OPTS := -pipe -dynamiclib -Os -Wall -Wno-implicit-int -fno-common
BUILD_OPTS += -prebind -headerpad_max_install_names -Wl,-search_paths_first
BUILD_OPTS += -Wl,-single_module -arch ppc -arch i386 -arch x86_64 
LIBRARY := $(LIBRARY).dylib
endif

RM := /bin/rm -f

all : $(LIBRARY)

$(LIBRARY) : $(OBJS)
	@echo "building and striping $@"
	@${CC} ${BUILD_OPTS} -o $@ $^ ${LDFLAGS}
ifeq ($(UNAME), OpenBSD)
	@${STRIP} $@
endif
ifeq ($(UNAME), Linux)
	@${STRIP} $@
endif

%.o: %.c
	@echo "compiling $<"
	@${CC} ${CFLAGS} -c -o $@ $<

%.o: %.cpp
	@echo "compiling $<"
	@${CC} ${CFLAGS} -c -o $@ $<

clean:
	@echo "cleaning... ${LIBRARY} ${OBJS}"
	@${RM} ${LIBRARY} ${OBJS}

